package com.lll.simple.rpc.protocol.handler;

import com.lll.simple.rpc.common.RpcFuture;
import com.lll.simple.rpc.common.RpcProtocol;
import com.lll.simple.rpc.common.RpcRequestHolder;
import com.lll.simple.rpc.common.RpcResponse;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

/**
 * @Author: liull
 * @Description:
 * @Date: Created in 15:22 2021/2/4
 * @Modified By:
 */
public class RpcResponseHandler extends SimpleChannelInboundHandler<RpcProtocol<RpcResponse>> {
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, RpcProtocol<RpcResponse> msg) throws Exception {
        long requestId = msg.getHeader().getRequestId();
        RpcFuture<RpcResponse> future = RpcRequestHolder.REQUEST_MAP.remove(requestId);
        future.getPromise().setSuccess(msg.getBody());
    }
}
